package com.lx.javasunmmrize.SingletonDemo;

/**
 * @Description 枚举实现单例模式
 *
 * 优点:避免线程安全问题,而且能防止反序列化重新创建新的对象,推荐使用
 *
 *
 * @Author lx
 * @Date 2021/2/23 22:45
 **/
public class SingletonTest08 {
    public static void main(String[] args) {
        Singleton08 instance1 = Singleton08.INSTANCE;
        Singleton08 instance2 = Singleton08.INSTANCE;
        System.out.println(instance1==instance2);
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());

        instance1.sayOk();

//        Runtime runTime = new Runtime() ;
    }
}


enum Singleton08{
    INSTANCE;

    public void sayOk(){
        System.out.println("ok");
    }

}